package org.test.springAOP.Example;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

@Aspect
@Repository("TheAspectExample")
public class TheAspect {

//	/**
//	 * 方法前
//	 */
//	@Before("execution(* org.test..*(..))")
//	public void before() {
//		System.out.println("这是spring beforeMethod");
//	}

//	/**
//	 * 返回值后，retVal为返回值
//	 * 
//	 * @param retVal
//	 */
//	@AfterReturning(pointcut = "execution(* org.test..*(..))", returning = "retVal", value = "vl")
//	public void afterReturn(Object retVal) {
//		System.out.println("这是spring aop afterReturn ");
//		System.out.println("返回值为:" + retVal.toString());
//		System.out.println("afterReturn");
//	}

//	/**
//	 * 这个可以从joinpoint中拿到类，方法，参数,注意，最后要 return joinpoint.proceed();
//	 */
//	@Around("execution(* org.test..*(..))")
//	public Object audit(ProceedingJoinPoint joinpoint) throws Throwable {
//		System.out.println("这是spring aop around");
//		Object[] params = joinpoint.getArgs();
//		for (int i = 0; i < params.length; i++) {
//			System.out.println(params[i]);
//		}
//		System.out.println(joinpoint.getSignature());
//		return joinpoint.proceed();
//	}

	@AfterThrowing(pointcut = "execution(* org.test..*(..))",
			throwing = "ex")
	public void doRecoveryActions(Exception ex) {
		System.out.println("这是spring afterThrowing begin");
		ex.printStackTrace();
		System.out.println("这是spring afterThrowing end");
		
	}

}